﻿<UserControl x:Class="XWord.GUI.Views.Fundamental.WordExplorerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:inf="http://www.grandsys.com/luna"
             xmlns:info="http://schemas.xword.com/winfx/xaml/info"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:ribbon="http://schemas.actiprosoftware.com/winfx/xaml/ribbon"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <Style x:Key="swapEllipse" TargetType="Ellipse">
            <Setter Property="Width" Value="14"></Setter>
            <Setter Property="Height" Value="14"></Setter>
            <Setter Property="Stroke" Value="Black"></Setter>
            <Setter Property="Margin" Value="5,0,0,0"></Setter>
        </Style>
        <ContextMenu x:Key="WordMenu"  cal:Action.TargetWithoutContext="{Binding PlacementTarget.Tag,RelativeSource={RelativeSource Mode=Self}}">
            <MenuItem Header="复制到搜索框" cal:Message.Attach="CopyWordToSearch"  />
            <MenuItem Header="删除" cal:Message.Attach="DeleteWord"  />
        </ContextMenu>
        
    </UserControl.Resources>
    <inf:DockingWindowMetadata.Instance>
        <inf:DockingWindowMetadata Title="{Binding DisplayName}" IsToolWindow="True"
                                    CanClose="False" CreateNewDockingGroup="True" />
    </inf:DockingWindowMetadata.Instance>
    <DockPanel>
        <!--<ScrollViewer>
            <info:ElementListBox ItemsSource="{Binding WordList,IsAsync=True}"
                                 SelectedItem="{Binding SelectedWord,Mode=TwoWay}"
                                 >
                <info:ElementListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </info:ElementListBox.ItemTemplate>
            </info:ElementListBox>
        </ScrollViewer>-->
        <!---->
        <ListBox x:Name="Element_WordList"
                 SelectionChanged="Element_WordList_SelectionChanged"
                 DockPanel.Dock="Bottom"
                 cal:Message.Attach="[Event Drop] = [Action AddWord($eventArgs.Data)]"
                 PreviewMouseRightButtonDown="Element_WordList_PreviewMouseRightButtonDown"
                  SelectedItem="{Binding SelectedItem}"
                  ItemsSource="{Binding WordList,IsAsync=True}">
            <info:MaskAttach.Content>
                <info:MaskAttach Open="{Binding IsOpen}" DataContext="{Binding DataContext,ElementName=Element_WordList}">
                    <info:MaskAttach.Template>
                        <DataTemplate>
                            <Border Background="Silver" Opacity="0.7">
                            <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center"
                                       Foreground="SteelBlue"
                                       FontSize="16"
                                       Text="{Binding WordTip}"/>
                            </Border>
                        </DataTemplate>
                    </info:MaskAttach.Template>
                </info:MaskAttach>
            </info:MaskAttach.Content>
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                    <Setter Property="Tag" Value="{Binding DataContext,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBox}}"></Setter>
                    <Setter Property="ContextMenu" Value="{StaticResource WordMenu}"></Setter>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
         <i:Interaction.Behaviors>
             <info:ScrollViewerTipBehavior />
         </i:Interaction.Behaviors>
        </ListBox>
        
    </DockPanel>

   
</UserControl>



<!--<WrapPanel>
                        <CheckBox IsChecked="{Binding IsSelected,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ListBoxItem}}"/>
                        <TextBlock Text="{Binding Name}"/>
                        <Ellipse x:Name="Word_Ignore" Style="{StaticResource swapEllipse}" ToolTip="高中词汇" Margin="20,0,0,0"
                         cal:Message.Attach="[Event MouseDown] = [Action MarkIsIgnore($this.DataContext)]"
                         Fill="Red" />
                    </WrapPanel>
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding IsIgnore}" Value="True">
                            <Setter Property="Fill" Value="Green" TargetName="Word_Ignore"></Setter>
                        </DataTrigger>
                    </DataTemplate.Triggers>-->
<!--<i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <info:ReadOnlyPropertyAction Property="SelectedItem" BindablePropertyItem="{Binding SelectedWord, Mode=TwoWay}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <i:Interaction.Behaviors>

                <info:MultiSelectOneBehavior/>

            </i:Interaction.Behaviors>-->